package com.yincheng.oes.business.util;

import java.util.UUID;
import org.apache.commons.lang3.StringUtils;

/**
 * @Author: yangsy
 * @Contact: 446948434@qq.com
 * @Date: 2021/8/22 22:46
 * @Version: 1.0
 * @Description:
 */
public class StringUtil {

    public static String valueOf(Object object) {
        if (object == null) {
            return null;
        }
        return String.valueOf(object);
    }

    public static String generateUUID() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 将导出到word中的特殊字符转义
     * @param str 带转换的字符串
     * @return 转义后的字符串
     */
    public static String transform(String str){
        if(StringUtils.isBlank(str)) {
            return str;
        }

        if(str.contains("<")||str.contains(">")||str.contains("&")){
            str=str.replaceAll("&", "&amp;");
            str=str.replaceAll("<", "&lt;");
            str=str.replaceAll(">", "&gt;");
        }

        return str;
    }

}
